﻿using JetBrains.ReSharper.Daemon.CSharp.Stages;
using JetBrains.ReSharper.Daemon.Stages;
using JetBrains.ReSharper.Daemon.Stages.Dispatcher;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using MugenMvvmToolkit.ReSharper.Highlighting;
using MugenMvvmToolkit.ReSharper.Infrastructure;

namespace MugenMvvmToolkit.ReSharper.ViewModels.Analyzers
{
    [ElementProblemAnalyzer(new[] { typeof(ITypeofExpression) },
        HighlightingTypes = new[] { typeof(InvalidViewModelTypeHighlighting) })]
    public class ViewModelTypeRequiredAnalyzer : ElementProblemAnalyzerBase<ITypeofExpression>
    {
        #region Overrides of ElementProblemAnalyzerBase<IClassDeclaration>

        protected override void Run(ITypeofExpression element, ElementProblemAnalyzerData data,
            IHighlightingConsumer consumer)
        {
            var cSharpArgument = element.Parent as ICSharpArgument;
            if (ToolkitExtensions.HasViewModelTypeRequiredAttribute(cSharpArgument) &&
                !element.ArgumentType.IsOfType(TypeProvider.ViewModelInterface))
                consumer.AddHighlighting(new InvalidViewModelTypeHighlighting(element));
        }

        #endregion
    }
}